<script type="text/x-template" id="notelist">
    <div>
        <div align="center">
            <div style="width: 500px">
                <div style="margin-top: 15px;">
                    <el-input placeholder="请输入内容" v-model="keyword"   class="input-with-select">
                        <el-button slot="append" id="search-btn"  icon="el-icon-search" @click="searchnote()"></el-button>
                    </el-input>
                </div>
            </div>
            <br>
            <div style="padding: 20px">
                <template>
                    <el-table
                            :data="tableData"
                            style="width: 100%;padding-top: 30px"
                            height="600">
                        <el-table-column
                                label="序号"
                                width="150px">
                            <template slot-scope="scope">{{ scope.$index+1 }}</template>
                        </el-table-column>
                        <el-table-column
                                label="标题"
                                width="450px">
                            <template slot-scope="scope" ><a @click="locationppreview(scope.row.id)">{{ scope.row.title }}</a></template>
                        </el-table-column>
                        <el-table-column
                                prop="tag"
                                label="标签"
                                width="250px">
                        </el-table-column>
                        <el-table-column
                                prop="viewnum"
                                label="点击次数"
                                width="250px">
                        </el-table-column>
                        <el-table-column
                                prop="createTime"
                                label="创建时间"
                                width="250px">
                        </el-table-column>
                        <el-table-column
                                label="操作"
                                width="200">
                            <template slot-scope="scope">
                                <el-button @click="updateNote(scope.row)" type="text" size="small">编辑</el-button>
                                <el-button type="text" @click="deleteNote(scope.row.id)" size="small">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                            background
                            @current-change="handleCurrentChange"
                            layout="total,prev, pager, next"
                            :total="total">
                    </el-pagination>
                </template>
            </div>
        </div>
    </div>
</script>
<script>
    let notelist={
        data() {
            return {
                activeIndex: '1',
                activeIndex2: '1',
                total:0,
                tableData: [],
                search:'',
                keyword:''
            }
        },
        template: '#notelist',
        created(){
            api.GET('/note/page',{'page':1,'size':10},(result)=> {
                this.tableData=result.data.records;
                this.total=result.data.total;
            })
        },
        methods: {
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
            },
            searchnote(){
                api.GET('/note/page',{'page':1,'size':10,'keyword':this.keyword},(result)=> {
                    this.tableData=result.data.records;
                    this.total=result.data.total;
                })
            },
            handleCurrentChange(val) {
                api.GET('/note/page',{'page':val,'size':10,'keyword':this.keyword},(result)=> {
                    this.tableData=result.data.records;
                    this.total=result.data.total;
                })
            },
            locationfref(href){
                window.open(href);
            },
            locationppreview(id){
                window.open('/page/contentinfo.html?obj='+id)
            },
            updateNote(obj){
                window.open(obj.updateUrl)
            },
            deleteNote(id){
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    api.GET('/note/delete',{'id':id},(result)=> {
                        if(result.code==0){
                            this.$message({
                                showClose: true,
                                message: '删除成功',
                                type: 'success'
                            });
                            local.reload();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    }
    Vue.component('notelist',notelist);
</script>